package com.isae.chattingapp;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RosterInfoAdapter extends BaseAdapter{
	
	private LayoutInflater inflater=null;
	List<RosterInfo> ListRoster;
	
	public RosterInfoAdapter(Activity activity, List<RosterInfo> ParaListRoster){
		ListRoster = new ArrayList<RosterInfo>();
		ListRoster = ParaListRoster;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return ListRoster.size();
	}

	@Override
	public RosterInfo getItem(int position) {
		return ListRoster.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	// the system enters here after:
	//1-doing listview.setAdapter(adapter)
	//2-scrolling
	//3-the InnerRosterInfo has changed(If the RostersInfo array is changed in the ListRosters activity
	// the system enters here also)
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			// LayoutInflater class is used to instantiate layout XML file into its corresponding View objects.
			convertView = inflater.inflate(R.layout.uniqueroster, null);
		}

		((TextView) convertView.findViewById(R.id.NameUserList)).setText(ListRoster.get(position).RosterName);
		((TextView) convertView.findViewById(R.id.Status)).setText(ListRoster.get(position).RosterStatus);

		return convertView;
	}

}
